package edu.pku.sei.mdabase.infrastructure;

import edu.pku.sei.mdabase.core.IElement;
import edu.pku.sei.mdabase.infrastructure.event.EventSource;
import edu.pku.sei.mdabase.infrastructure.event.IEventListener;
import edu.pku.sei.mdabase.infrastructure.event.MTEvent;


public abstract class Element implements IElement, Cloneable {

	private boolean changeable = true;
	
	private EventSource eventSource = new EventSource();
	
	public void sendEvent(Object source,Object type, Object... data){
		eventSource.sendEvent(new MTEvent(source,type, data));			
	}
	
	public void sendEvent(MTEvent e){
		eventSource.sendEvent(e);
	}
	
	public void addListener(IEventListener el){
		eventSource.regist(el);
	}

	public boolean isChangeable() {
		return changeable;
	}

	public void setChangeable(boolean changeable) {
		this.changeable = changeable;
	}
	
	
	@Override
	public Object clone(){
		Object o = null;
		try {
			o = super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
	
}
